// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-16

package counter

import (
	"sync/atomic"
)

type (
	LoggingCounter interface {
		GetDiscardCount() int64
		GetFailedCount() int64
		GetPopCount() int64
		GetPushCount() int64
		GetSucceedCount() int64

		IncrDiscardCount(n int64)
		IncrFailedCount(n int64)
		IncrPopCount(n int64)
		IncrPushCount(n int64)
		IncrSucceedCount(n int64)
	}

	logging struct {
		DiscardCount int64
		FailedCount  int64
		PopCount     int64
		PushCount    int64
		SucceedCount int64
	}
)

func (o *logging) GetDiscardCount() int64 { return atomic.LoadInt64(&o.DiscardCount) }
func (o *logging) GetFailedCount() int64  { return atomic.LoadInt64(&o.FailedCount) }
func (o *logging) GetPopCount() int64     { return atomic.LoadInt64(&o.PopCount) }
func (o *logging) GetPushCount() int64    { return atomic.LoadInt64(&o.PushCount) }
func (o *logging) GetSucceedCount() int64 { return atomic.LoadInt64(&o.SucceedCount) }

func (o *logging) IncrDiscardCount(n int64) { atomic.AddInt64(&o.DiscardCount, n) }
func (o *logging) IncrFailedCount(n int64)  { atomic.AddInt64(&o.FailedCount, n) }
func (o *logging) IncrPopCount(n int64)     { atomic.AddInt64(&o.PopCount, n) }
func (o *logging) IncrPushCount(n int64)    { atomic.AddInt64(&o.PushCount, n) }
func (o *logging) IncrSucceedCount(n int64) { atomic.AddInt64(&o.SucceedCount, n) }

func (o *logging) init() *logging {
	return o
}
